import Vue from "vue";
import Router from "vue-router";

Vue.use(Router);

/* Layout */
import Layout from "@/layout";

/* Router Modules */
// import componentsRouter from './modules/components'
// import chartsRouter from './modules/charts'
// import tableRouter from './modules/table'
// import nestedRouter from './modules/nested'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    noCache: true                if set true, the page will no be cached(default is false)
    affix: true                  if set true, the tag will affix in the tags-view
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
    {
        path: "/redirect",
        component: Layout,
        hidden: true,
        children: [
            {
                path: "/redirect/:path(.*)",
                component: () => import("@/views/redirect/index")
            }
        ]
    },
    {
        path: "/login",
        component: () => import("@/views/login/index"),
        hidden: true
    },
    {
        path: "/signin-oidc",
        component: () => import("@/views/login/sso-login"),
        hidden: true
    },
    {
        path: "/save-auth",
        component: () => import("@/views/login/save-auth"),
        hidden: true
    },
    {
        path:"/redirect-silentrenew",
        component: () => import("@/views/login/sso-login"),
        hidden: true
    },
    {
        path: "/auth-redirect",
        component: () => import("@/views/login/auth-redirect"),
        hidden: true
    },
    {
        path: "/404",
        component: () => import("@/views/error-page/404"),
        hidden: true
    },
    {
        path: "/401",
        component: () => import("@/views/error-page/401"),
        hidden: true
    },
    {
        path: "/",
        component: Layout,
        redirect: "/dashboard",
        children: [
            {
                path: "dashboard",
                component: () => import("@/views/dashboard/index"),
                name: "Dashboard",
                meta: { title: "系统主页", icon: "home", affix: true }
            }
        ]
    },
    {
        path: "/company-management",
        component: Layout,
        redirect: "/company-management/index",
        meta: { title: "公司经营", icon: "gongsi", noCache: true },
        children: [
            {
                path: "companyManagement",
                component: () => import("@/views/company-management/page/companyManagement"),
                name: "companyManagement",
                meta: { title: "公司运营", icon: "", affix: true }
            },
            {
                path: "financialMaintenance",
                component: () => import("@/views/company-management/page/financialMaintenance"),
                name: "financialMaintenance",
                meta: { title: "财务数据维护", icon: "", affix: true }
            },
            {
                path: "projectCost",
                component: () => import("@/views/company-management/page/projectCost"),
                name: "projectCost",
                meta: { title: "项目成本查询", icon: "", affix: true }
            }
        ]
    },
    {
        path: "/divisional-manage",
        component: Layout,
        children: [
            {
                path: "home",
                component: () => import("@/views/divisional-manage/page/divisionalHome"),
                name: "divisionalHome",
                meta: { title: "事业部经营", icon: "jingying", affix: true }
            }
        ]
    },
    {
        path: "/project-management",
        component: Layout,
        children: [
            {
                path: "index",
                component: () => import("@/views/project-management/index"),
                name: "ProjectManagement",
                meta: { title: "项目管理", icon: "xiangmuguanli", affix: true }
            }
        ]
    },
    {
        path: "/table",
        component: Layout,
        children: [
            {
                path: "index",
                component: () => import("@/views/table/drag-table/"),
                name: "Documentation",
                meta: { title: "会议管理", icon: "huiyishi", affix: true }
            }
        ]
    },
    {
        path: "/material-management",
        component: Layout,
        redirect: "/material-management/index",
        meta: { title: "装配物料管理", icon: "xiangmu", noCache: true },
        children: [
            {
                path: "upload-bom",
                component: () => import("@/views/material-management/pages/upload-bom"),
                name: "MaterialManagement",
                meta: { title: "BOM上传", icon: "", noCache: true }
            },
            {
                path: "project-management",
                component: () => import("@/views/material-management/pages/project-management"),
                name: "ProjectManagement",
                meta: { title: "项目管理", icon: "", noCache: true },
            },
            {
                path: "/station-list",
                component: () => import("@/views/material-management/pages/station-list"),
                name: "StationList",
                meta: { title: "工位清单", icon: "", noCache: true },
                hidden:true
            },
            {
                path: "station-management",
                component: () => import("@/views/material-management/pages/station-management"),
                name: "StationManagement",
                meta: { title: "工位管理", icon: "", noCache: true }
            },
            {
                path: "machine-management",
                component: () =>
                    import("@/views/material-management/pages/machine"),
                name: "MachineManagement",
                meta: { title: "设备管理", icon: "", noCache: true }
            },
            {
                path: "machine-list",
                component: () =>
                    import("@/views/material-management/pages/machine-list"),
                name: "MachineList",
                meta: { title: "设备列表", icon: "", noCache: true },
                hidden:true
            },
            {
                path: "bom-management",
                component: () => import("@/views/material-management/pages/bom-management"),
                name: "BomManagement",
                meta: { title: "BOM管理", icon: "", noCache: true },
            },
            {
                path: "bom-list",
                component: () => import("@/views/material-management/pages/bom-list"),
                name: "BomList",
                meta: { title: "BOM清单", icon: "", noCache: true },
                hidden:true
            },
            {
                path: "material-statistics",
                component: () => import("@/views/material-management/pages/material-statistics"),
                name: "MaterialStatistics",
                meta: { title: "物料用量统计", icon: "", noCache: true }
            },
            {
                path: "material-type",
                component: () => import("@/views/material-management/pages/material-type"),
                name: "MaterialType",
                meta: { title: "物料类型", icon: "", noCache: true }
            },
            {
                path: "define-material",
                component: () => import("@/views/material-management/pages/define-material"),
                name: "DefineMaterial",
                meta: { title: "物料定义", icon: "", noCache: true }
            }
        ]
    },
    {
        path: "/profile",
        component: Layout,
        redirect: "/profile/index",
        children: [
            {
                path: "index",
                component: () => import("@/views/profile/index"),
                name: "Profile",
                meta: { title: "ERP管理", icon: "ERPguanli", noCache: true }
            }
        ]
    },
    // 系统管理
    {
        path: "/system-management",
        component: Layout,
        redirect: "/system-management/user",
        meta: { title: "系统管理", icon: "xiangmu", noCache: true },
        children: [
            // {
            //   path: 'index',
            //   component: () => import('@/views/system-management/index'),
            //   name: 'SystemManagement',
            //   meta: { title: '系统管理', icon: 'xitong', noCache: true }
            // },
            {
                path: "user",
                component: () =>
                    import("@/views/system-management/pages/userManagement"),
                name: "userManagement",
                meta: { title: "用户管理", icon: "xitong", noCache: true }
            },
            {
                path: "role",
                component: () =>
                    import("@/views/system-management/pages/roleManagement"),
                name: "roleManagement",
                meta: { title: "角色管理", icon: "xitong", noCache: true }
            },
            {
                path: "menu",
                component: () =>
                    import("@/views/system-management/pages/menuManagement"),
                name: "menuManagement",
                meta: { title: "菜单管理", icon: "xitong", noCache: true }
            },
            {
                path: "depart",
                component: () =>
                    import("@/views/system-management/pages/departManagement"),
                name: "departManagement",
                meta: { title: "部门管理", icon: "xitong", noCache: true }
            },
            {
                path: "post",
                component: () =>
                    import("@/views/system-management/pages/postManagement"),
                name: "postManagement",
                meta: { title: "岗位管理", icon: "xitong", noCache: true }
            },
            {
                path: "list",
                component: () => import("@/views/example/list"),
                name: "ArticleList",
                meta: { title: "Article List", icon: "list" }
            }
        ]
    },
    //部门管理
    {
        path: "/department-management",
        component: Layout,
        redirect: "/department-management/designReferenceLibrary/templateManagement",
        name: 'department-management',
        meta: { title: "部门管理", icon: "peoples", noCache: true },
        children: [
            {
                path: "designReferenceLibrary",
                component: () => import("@/views/department-management/designReferenceLibrary/index"),
                name: "designReferenceLibrary",
                redirect: "/department-management/designReferenceLibrary/templateManagement",
                meta: { title: "设计参考库", icon: "", noCache: true },
                children: [
                    {
                      path: 'template',
                      component: () => import('@/views/department-management/designReferenceLibrary/templateManagement'),
                      name: 'template',
                      meta: { title: '模板管理' }
                    },
                    {
                      path: 'downlod',
                      component: () => import('@/views/department-management/designReferenceLibrary/downlodApproval'),
                      name: 'downlod',
                      meta: { title: '下载申请审核' }
                    },
                    {
                      path: 'query',
                      component: () => import('@/views/department-management/designReferenceLibrary/queryDataEntry'),
                      name: 'query',
                      meta: { title: '资料录入查询' }
                    },
                ]
            },
        ]
    },
    // {
    //     path: "/dome",
    //     component: Layout,
    //     children: [
    //         {
    //             path: "dome",
    //             component: () => import("@/views/dome/dome"),
    //             name: "Tab",
    //             meta: { title: "dome", icon: "el-icon-s-home" }
    //         }
    //     ]
    // },
    {
        path: "/home",
        component: Layout,
        children: [
            {
                path: "index",
                component: () => import("@/views/home/index"),
                name: "Tab",
                meta: { title: "首页后台管理", icon: "el-icon-s-home" }
            }
        ]
    },

    {
        path: "/tab",
        component: Layout,
        children: [
            {
                path: "index",
                component: () => import("@/views/tab/index"),
                name: "Tab",
                meta: { title: "Tab", icon: "tab" }
            }
        ]
    },

    {
        path: "/error",
        component: Layout,
        redirect: "noRedirect",
        name: "ErrorPages",
        meta: {
            title: "Error Pages",
            icon: "404"
        },
        childrens: [
            {
                path: "depart",
                component: () =>
                    import("@/views/system-management/pages/departManagement"),
                name: "departManagement",
                meta: { title: "部门管理", icon: "xitong", noCache: true }
            },
            {
                path: "post",
                component: () =>
                    import("@/views/system-management/pages/postManagement"),
                name: "postManagement",
                meta: { title: "岗位管理", icon: "xitong", noCache: true }
            }
        ]
    },
    {
        path: "/system-watch",
        component: Layout,
        redirect: "/system-watch/index",
        children: [
            {
                path: "index",
                component: () => import("@/views/system-watch/index"),
                name: "SystemWatch",
                meta: {
                    title: "系统监控",
                    icon: "xitongjiankong",
                    noCache: true
                }
            }
        ]
    }
];

/**
 * asyncRoutes
 * the routes that need to be dynamically loaded based on user roles
 */
// export const asyncRoutes = [
//   {
//     path: '/permission',
//     component: Layout,
//     redirect: '/permission/page',
//     alwaysShow: true, // will always show the root menu
//     name: 'Permission',
//     meta: {
//       title: 'Permission',
//       icon: 'lock',
//       roles: ['admin', 'editor'] // you can set roles in root nav
//     },
//     children: [
//       {
//         path: 'page',
//         component: () => import('@/views/permission/page'),
//         name: 'PagePermission',
//         meta: {
//           title: 'Page Permission',
//           roles: ['admin'] // or you can only set roles in sub nav
//         }
//       },
//       {
//         path: 'directive',
//         component: () => import('@/views/permission/directive'),
//         name: 'DirectivePermission',
//         meta: {
//           title: 'Directive Permission'
//           // if do not set roles, means: this page does not require permission
//         }
//       },
//       {
//         path: 'role',
//         component: () => import('@/views/permission/role'),
//         name: 'RolePermission',
//         meta: {
//           title: 'Role Permission',
//           roles: ['admin']
//         }
//       }
//     ]
//   },

//   {
//     path: '/icon',
//     component: Layout,
//     children: [
//       {
//         path: 'index',
//         component: () => import('@/views/icons/index'),
//         name: 'Icons',
//         meta: { title: 'Icons', icon: 'icon', noCache: true }
//       }
//     ]
//   },

//   /** when your routing map is too long, you can split it into small modules **/
//   componentsRouter,
//   chartsRouter,
//   nestedRouter,
//   tableRouter,

//   {
//     path: '/example',
//     component: Layout,
//     redirect: '/example/list',
//     name: 'Example',
//     meta: {
//       title: 'Example',
//       icon: 'el-icon-s-help'
//     },
//     children: [
//       {
//         path: 'create',
//         component: () => import('@/views/example/create'),
//         name: 'CreateArticle',
//         meta: { title: 'Create Article', icon: 'edit' }
//       },
//       {
//         path: 'edit/:id(\\d+)',
//         component: () => import('@/views/example/edit'),
//         name: 'EditArticle',
//         meta: { title: 'Edit Article', noCache: true, activeMenu: '/example/list' },
//         hidden: true
//       },
//       {
//         path: 'list',
//         component: () => import('@/views/example/list'),
//         name: 'ArticleList',
//         meta: { title: 'Article List', icon: 'list' }
//       }
//     ]
//   },

//   {
//     path: '/tab',
//     component: Layout,
//     children: [
//       {
//         path: 'index',
//         component: () => import('@/views/tab/index'),
//         name: 'Tab',
//         meta: { title: 'Tab', icon: 'tab' }
//       }
//     ]
//   },

//   {
//     path: '/error',
//     component: Layout,
//     redirect: 'noRedirect',
//     name: 'ErrorPages',
//     meta: {
//       title: 'Error Pages',
//       icon: '404'
//     },
//     children: [
//       {
//         path: '401',
//         component: () => import('@/views/error-page/401'),
//         name: 'Page401',
//         meta: { title: '401', noCache: true }
//       },
//       {
//         path: '404',
//         component: () => import('@/views/error-page/404'),
//         name: 'Page404',
//         meta: { title: '404', noCache: true }
//       }
//     ]
//   },

//   {
//     path: '/error-log',
//     component: Layout,
//     children: [
//       {
//         path: 'log',
//         component: () => import('@/views/error-log/index'),
//         name: 'ErrorLog',
//         meta: { title: 'Error Log', icon: 'bug' }
//       }
//     ]
//   },

//   {
//     path: '/excel',
//     component: Layout,
//     redirect: '/excel/export-excel',
//     name: 'Excel',
//     meta: {
//       title: 'Excel',
//       icon: 'excel'
//     },
//     children: [
//       {
//         path: 'export-excel',
//         component: () => import('@/views/excel/export-excel'),
//         name: 'ExportExcel',
//         meta: { title: 'Export Excel' }
//       },
//       {
//         path: 'export-selected-excel',
//         component: () => import('@/views/excel/select-excel'),
//         name: 'SelectExcel',
//         meta: { title: 'Export Selected' }
//       },
//       {
//         path: 'export-merge-header',
//         component: () => import('@/views/excel/merge-header'),
//         name: 'MergeHeader',
//         meta: { title: 'Merge Header' }
//       },
//       {
//         path: 'upload-excel',
//         component: () => import('@/views/excel/upload-excel'),
//         name: 'UploadExcel',
//         meta: { title: 'Upload Excel' }
//       }
//     ]
//   },

//   {
//     path: '/zip',
//     component: Layout,
//     redirect: '/zip/download',
//     alwaysShow: true,
//     name: 'Zip',
//     meta: { title: 'Zip', icon: 'zip' },
//     children: [
//       {
//         path: 'download',
//         component: () => import('@/views/zip/index'),
//         name: 'ExportZip',
//         meta: { title: 'Export Zip' }
//       }
//     ]
//   },

//   {
//     path: '/pdf',
//     component: Layout,
//     redirect: '/pdf/index',
//     children: [
//       {
//         path: 'index',
//         component: () => import('@/views/pdf/index'),
//         name: 'PDF',
//         meta: { title: 'PDF', icon: 'pdf' }
//       }
//     ]
//   },
//   {
//     path: '/pdf/download',
//     component: () => import('@/views/pdf/download'),
//     hidden: true
//   },

//   {
//     path: '/theme',
//     component: Layout,
//     children: [
//       {
//         path: 'index',
//         component: () => import('@/views/theme/index'),
//         name: 'Theme',
//         meta: { title: 'Theme', icon: 'theme' }
//       }
//     ]
//   },

//   {
//     path: '/clipboard',
//     component: Layout,
//     children: [
//       {
//         path: 'index',
//         component: () => import('@/views/clipboard/index'),
//         name: 'ClipboardDemo',
//         meta: { title: 'Clipboard', icon: 'clipboard' }
//       }
//     ]
//   },

//   {
//     path: 'external-link',
//     component: Layout,
//     children: [
//       {
//         path: 'https://github.com/PanJiaChen/vue-element-admin',
//         meta: { title: 'External Link', icon: 'link' }
//       }
//     ]
//   },

//   // 404 page must be placed at the end !!!
//   { path: '*', redirect: '/404', hidden: true }
// ]

export const asyncRoutes = [];

const createRouter = () =>
    new Router({
        mode: 'history', // require service support
        scrollBehavior: () => ({ y: 0 }),
        routes: constantRoutes
    });

const router = createRouter();

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
    const newRouter = createRouter();
    router.matcher = newRouter.matcher; // reset router
}

export default router;
